<%@ page language="java" contentType="text/html; charset=utf-8"%>
<%@ taglib  prefix="s"  uri="/struts-tags"%> 
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

	<div class="easyui-layout"  data-options="fit:true">
		
		<div data-options="region:'west',split:true" title="药品分类" style="width:150px;">
			<ul id="tt"></ul>
		</div>
		<div data-options="region:'center',title:'药品列表'" style="background:#fafafa;overflow:hidden">
			<table   id='select_med_grid'
					data-options="url:'searchMedinfo.do',border:false,fit:true,fitColumns:true,pagination:true">
				<thead>
					<tr>
						<th data-options="field:'medid',hidden:true" >药品id</th>
						<th data-options="field:'medname'" width="80">药品名称</th>
						<th data-options="field:'medtypename'" width="80">分类</th>
						<th data-options="field:'code'" width="80">编码</th>
						<th data-options="field:'factname'" width="100">生产厂家</th>
						<th data-options="field:'spec',align:'right'" width="80">规格</th>
					</tr>
				</thead>
			</table>
		</div>
	</div>
	
	<div id="search_medinfo" style="padding:5px;height:auto">  
  		<div>
  			药品名称:   
	        <input name="medname" id="medname_select" class="easyui-validatebox" style="width:100px"  type="text">  
	        分类:   
	        <input name="medtypename" id="medtypename" class="easyui-validatebox" style="width:100px"  type="text" readonly="readonly">
	        <input name="medtypeid" id="medtypeid" class="easyui-validatebox" style="width:100px"  type="hidden" readonly="readonly">    
	        药品编码:   
	        <input name="medcode" id="medcode" class="easyui-validatebox" style="width:100px"  type="text">  
	        生产厂家:   
	        <input name="factname" id="factname_search_med" class="easyui-validatebox" style="width:100px"  type="text">  
	         <a href="javascript:void();" class="easyui-linkbutton" iconCls="icon-search" id='btnSearch_medinfo'>搜索</a>
	         <a href="javascript:void();" class="easyui-linkbutton" iconCls="icon-search" id='btnReset_medinfo'>重置</a>    
	    </div> 
	</div>  

<script type="text/javascript">
$(function(){
	$('#tt').tree({  
	    url:'<%=basePath%>/contmaster_ajaxShowMedTypeTree.do' ,
	    onBeforeExpand:function(node,param){  
                     $('#tt').tree('options').url = "<%=basePath%>/contmaster_ajaxShowMedTypeTree.do?id=" + node.id;
                 }, 
	    type:'post' ,
	    dataType:'json',
	    onClick: function(node){
			//alert(node.id);  
			var b = $(this).tree('isLeaf', node.target); 
			if(b==true){
				$("#medtypename").val(node.text);
				$("#medtypeid").val(node.id);
				//按分类加载数据
				$("#btnSearch_medinfo").click();
			}
		}
		    
	}); 
	
	$('#select_med_grid').datagrid({
		toolbar:"#search_medinfo",
		url:'searchMedinfo.do',
		onDblClickRow: function(rowIndex,rowData){
   			$("#medid").val(rowData['medid']);
   			$("#medname").val(rowData['medname']);
   			$("#factname").html(rowData['factname']);
   			$("#price").val(rowData['pricetop']);
   			$('#win_select_med').window("close");
		}
	});
	
	$("#btnSearch_medinfo").click(function(){
			$('#select_med_grid').datagrid({
				//url:'contmaster_search.do',
			    queryParams:{
			    	medname:$("#medname_select").val(),
			    	medtypeid:$("#medtypeid").val(),
			    	medcode:$("#medcode").val(),
			    	factname:$("#factname_search_med").val()
			    },
			});
			$('#select_med_grid').datagrid("load");
		});
		
	$("#btnReset_medinfo").click(function(){
		$("#medname_select,#medtypename,#medtypeid, #medcode,#factname_search_med").val("");
	});
});
</script>	
